# -*- coding: utf-8 -*-
import tornado.web
import tornado.ioloop
import tornado.httpserver

from tornado.options import define
from app.configs import configs, global_config, options
print(global_config)
from app.urls import urls

import pymysql
pymysql.install_as_MySQLdb()


define("port", type=int, default=global_config['port'])


class Valkyrja(tornado.web.Application):
    def __init__(self):
        super(Valkyrja, self).__init__(handlers=urls, **configs)


def create_server():
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(Valkyrja())
    print("Listen on port {}", options.port)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
